package com.fyx.controller;

import com.alibaba.fastjson.JSONObject;
import com.fyx.annotation.Log;
import com.fyx.entity.*;
import com.fyx.service.IPayAnalysisService;
import com.fyx.utils.PageUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Pageable;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

@Api(tags = "付费分析")
@RestController
@RequestMapping("/api/payAnalysis")
@RequiredArgsConstructor
public class PayAnalysisController {
    @Autowired
    private IPayAnalysisService iPayAnalysisService;

    @Log("查询充值数据")
    @ApiOperation("查询充值数据")
    @GetMapping(value="charge")
    @PreAuthorize("@el.check('charge:list')")
    public ResponseEntity<Object> charge(ChargeData chargeData, Pageable pageable){
        Map mapResult = iPayAnalysisService.charge(chargeData,pageable);
        return new ResponseEntity<>(PageUtil.toPage(mapResult.get("list"),mapResult.get("total")), HttpStatus.OK);
    }

    @Log("查询道具消耗")
    @ApiOperation("查询道具消耗")
    @GetMapping(value="props")
    @PreAuthorize("@el.check('props:list')")
    public ResponseEntity<Object> props(PropsData propsData, Pageable pageable){
        Map mapResult = iPayAnalysisService.props(propsData,pageable);
        return new ResponseEntity<>(PageUtil.toPage(mapResult.get("list"),mapResult.get("total")), HttpStatus.OK);
    }

    @Log("查询付费排行榜")
    @ApiOperation("查询付费排行榜")
    @GetMapping(value = "ranking")
    @PreAuthorize("@el.check('ranking:list')")
    public ResponseEntity<Object> ranking(OrderEntity orderEntity, Pageable pageable){
        Map mapResult = iPayAnalysisService.ranking(orderEntity,pageable);
        return new ResponseEntity<>(PageUtil.toPage(mapResult.get("list"),mapResult.get("total")), HttpStatus.OK);

    }

    @Log("道具消耗分类统计")
    @ApiOperation("道具消耗分类统计")
    @GetMapping(value = "propsOverview")
    @PreAuthorize("@el.check('propsOverview:list')")
    public ResponseEntity<Object> propsOverview(Overview overview, Pageable pageable){
        overview.setOverviewType("0");
        Map mapResult = iPayAnalysisService.propsOverview(overview,pageable);
        return new ResponseEntity<>(PageUtil.toPage(mapResult.get("list"),mapResult.get("total")), HttpStatus.OK);
    }

    @Log("道具卡消耗购买统计")
    @ApiOperation("道具卡消耗购买统计")
    @GetMapping(value = "propsCard")
    @PreAuthorize("@el.check('propsCard:list')")
    public ResponseEntity<Object> propsCard(CardInfoEntity cardInfoEntity, Pageable pageable){
        Map mapResult = iPayAnalysisService.propsCard(cardInfoEntity,pageable);
        return new ResponseEntity<>(PageUtil.toPage(mapResult.get("list"),mapResult.get("total")), HttpStatus.OK);
    }

    @Log("查询购买详细数据")
    @ApiOperation("查询购买详细数据")
    @GetMapping(value="chargeBuyProps")
    @PreAuthorize("@el.check('chargeBuyProps:list')")
    public Map chargeBuyProps(PropsInfoEntity propsInfoEntity, Pageable pageable){
        Map mapResult = iPayAnalysisService.chargeBuyProps(propsInfoEntity,pageable);
        return  mapResult;
    }

    @PostMapping(value = "getChargeBuyProps")
    @PreAuthorize("@el.check('chargeBuyProps:list')")
    public List<Map> getChargeBuyProps(@Validated @RequestBody JSONObject jsonObject){
        Integer time=Integer.valueOf(jsonObject.getString("time")) ;
        String channel=jsonObject.getString("channel");
        List<Map> getMaiRoomsInfo = iPayAnalysisService.getChargeBuyProps( time,channel);
        return getMaiRoomsInfo;
    }


    @PostMapping(value = "getPropsCard")
    @PreAuthorize("@el.check('propsCard:list')")
    public List<CardInfoEntity> getPropsCard(@Validated @RequestBody JSONObject jsonObject){
        Integer time=Integer.valueOf(jsonObject.getString("time")) ;
        String channel=jsonObject.getString("channel");
        List<CardInfoEntity> getMaiRoomsInfo = iPayAnalysisService.propsCard(time,channel);
        return getMaiRoomsInfo;
    }

}
